package me.learningandroid.ch2_5.returnstackdemo;

import android.app.Activity;

import java.util.LinkedList;
import java.util.List;

public class ActivityCollector {
    private List<Activity> activities;
    private static ActivityCollector instance = new ActivityCollector();

    public static ActivityCollector getInstance() {
        return instance;
    }

    private ActivityCollector() {
        activities = new LinkedList<>();
    }

    public void onActivityCreated(Activity activity) {
        activities.add(activity);
    }

    public void onActivityDestroyed(Activity activity) {
        activities.remove(activity);
    }

    public void oneClickFinish() {
        for (Activity act: activities) {
            act.finish();
        }
    }
}
